<template>
<div>
    <we-nav-bar></we-nav-bar>
    <div style="margin-bottom: 150px">
        <van-row>
            <van-col span="24">
                <div style="margin-left: 1rem">
                    <p>当前 : {{now.name}}</p>
                </div>
            </van-col>
        </van-row>

        <van-cell title="消费金额" :value="data.xfje+'元'" size="large"  />
        <van-cell title="预交款金额" :value="data.Yjje+'元'" size="large"  />
        <van-cell title="剩余金额" :value="data.SYJE+'元'" size="large"  />

        <van-cell-group>
            <van-field
                    v-model="jiage"
                    required
                    label="预交金充值"
                    placeholder="请输入要充值的金额"
            />
        </van-cell-group>
        <van-button v-show="kai" type="primary" @click="chongzhi"  style="margin-left:40%;margin-top: 5%;">立即充值</van-button>

        <van-row>
            <van-col>
                <van-action-sheet v-model="show" :actions="users" @select="onSelect" />
            </van-col>
        </van-row>
    </div>
    <div class="btn-block" style="background: white;margin: 0;width: 100%;padding-top: 8px;text-align: center">
        <van-row>
            <van-col span="22" offset="1">
                <van-button  type="info" @click="selectUser" style="border-radius: 0.2rem;overflow: hidden" size="large">切换就诊人</van-button>
            </van-col>
        </van-row>
    </div>
</div>
</template>

<script>
    export default {
        name: "jinge",
        data(){
            return{
                url:'/app/wechat/Zjzf/',
                data:{
                    xfje:0,
                    Yjje:0,
                    SYJE:0,
                },
                jiage:"",
                ip:"",
                kai:true,
                show:false,
                users:[],
                now:{
                    name:'',
                    id_code:'',
                },
            }
        },
        created() {
            this.getUsers();
            this.currentMan();
        },
        methods:{
            getInfo(id_code){
                this.http.post("/app/wechat/Wujiacha/yujiaojin/mid/2", {sfz: id_code}).then(res=>{
                    if (res.data.error==1){
                        this.kai = false;
                        this.$notify({type:"warning",message:"未查询到账户信息"})
                    }else{
                        if(res.data.info.error===1){
                            this.kai=false
                            alert('请先进行实名认证')
                        }else{
                            this.kai = true;
                            this.data=res.data.info
                            this.ip=res.data.info.wechat_ip
                        }
                    }
                })
            },
            chongzhi(){
                if (this.jiage=="" || this.jiage==0){
                    alert("请输入要充值的金额")
                }else{
                    window.location.href=this.ip+"/app/wechat/WujiachaPlay/index/jinge/"+this.jiage+"/id_code/"+this.now.id_code+"/mid/2"
                }
            },
            //当前患者
            currentMan(){
                if(window.localStorage.getItem("current_patient_name") && window.localStorage.getItem("current_patient_ID")){
                    this.now.name = window.localStorage.getItem("current_patient_name");
                    this.now.id_code = window.localStorage.getItem("current_patient_ID");
                    this.getInfo(this.now.id_code);
                }else{
                    this.getLoginUser();
                }
            },
            //获取用户列表
            getUsers(){
                this.axios.post('/app/wechat/record/huanzhe/mid/2.html').then(({data}) => {
                    if(data.error===0){
                        this.users = data.info
                    }
                })
            },
            //点击按钮
            selectUser(){
                this.show = !this.show;
            },
            //获取当前登录人
            getLoginUser(){
                this.axios.post(this.url + 'loguser/mid/2.html').then(({data}) => {
                    if(data.code===0){
                        this.now = data.data
                        this.getInfo(this.now.id_code);
                    }
                })
            },
            //选择用户
            onSelect(item){
                this.now.name = item.name;
                this.now.id_code = item.id_code;
                window.localStorage.setItem("current_patient_name",item.name)
                window.localStorage.setItem("current_patient_ID",item.id_code)
                this.getInfo(this.now.id_code);
                this.show = false;
            },
        }
    }
</script>

<style scoped>
.van-cell__value{
    color: red;
}
.van-button--primary{
    background-color: #3E76D7;
    border:1px solid #3E76D7;
}
.btn-block{
    position: fixed;
    bottom: 5px;
}
</style>
